// booking-seats.js
var store_id = '';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        date: '',
        time: '',
        people: '',
        usernme: '',
        phone: '',
        desc: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        store_id = options.id
        console.log(store_id)
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },


    bindDateChange: function (e) {
        this.setData({
            date: e.detail.value
        })
    },
    bindTimeChange: function (e) {
        this.setData({
            time: e.detail.value
        })
    },
    dateEvent: function (e) {
        this.setData({
            date: e.detail.value
        })
    },
    timeEvent: function (e) {
        this.setData({
            time: e.detail.value
        })
    },
    usernameEvent: function (e) {
        this.setData({
            username: e.detail.value
        })
    },
    peopleEvent: function (e) {
        this.setData({
            people: e.detail.value
        })
    },
    mobileEvent: function (e) {
        this.setData({
            mobile: e.detail.value
        })
    },
    descEvent: function (e) {
        this.setData({
            desc: e.detail.value
        })
    },
    submit: function () {
        var date = this.data.date
        var time = this.data.time
        var booking_time = date + ' ' + time
        var people = this.data.people
        var username = this.data.username
        var mobile = this.data.mobile
        var desc = this.data.desc
        var that = this
        if (!date || !time) {
            wx.showToast({
                title: "请填写订座时间",
                duration:2000
            })
            return;
        }
        if (!people) {
            wx.showToast({
                title: "请填写用餐人数",
                duration:2000
            })
            return;
        }
        if (!username) {
            wx.showToast({
                title: "请填写联系人",
                duration:2000
            })
            return;
        }
        if (!getApp().globalData.rex.test(mobile)) {
          wx.showToast({
            title: '请输入正确的手机号码',
            icon: '',
            image: '',
            duration: 0,
            mask: true,
            success: function (res) { },
            fail: function (res) { },
            complete: function (res) { },
          })
          return;
        }
        if (!mobile) {
            wx.showToast({
                title: "请填写联系电话",
                duration:2000
            })
            return;
        }
        getApp().http.request({
            url: '/api/v1/booking_seat/create?id=' + store_id + '&booking_time=' + booking_time + '&people=' + people + '&username=' + username + '&mobile=' + mobile + '&desc=' + desc,
            method: 'POST',
            data: {},
            dataType: 'json',
            success: function (res) {
                console.log(res.data.data)
                if (res.data.code == 200) {
                    wx.showToast({
                        title: '订座成功',
                        duration:2000,
                        complete: function () {
                            wx.navigateBack({
                                delta: 1
                            })
                        }
                    })
                } else {
                    wx.showToast({
                        title: res.data.msg,
                        duration:2000
                    })
                }
            },
            fail: function () {

            }
        })
    }
})